/*
 * @Description:
 * @Author: Cxy
 * @Date: 2023-04-23 15:07:55
 * @LastEditors: Cxy
 * @LastEditTime: 2023-07-12 22:37:32
 * @FilePath: \blogGitee\blogAdmin\play\src\views\login\component\rules.ts
 */
import type { FormRules } from 'element-plus'
import I18n from '@/hooks/I18n'

const REGEXP_PWD =
  /^(?![0-9]+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?!^.*[\u4E00-\u9FA5].*$)([^(0-9a-zA-Z)]|[()]|[a-z]|[A-Z]|[0-9]){8,18}$/

export default function () {
  const { tt } = I18n()
  const passWordRule = reactive(<FormRules>{
    loginCode: [
      {
        validator: (_, value, callback) => {
          if (!value) return callback(new Error(tt.value('loginReg.promptAccountText')))
          callback()
        },
        trigger: 'blur'
      }
    ],
    passWord: [
      {
        validator: (_, value, callback) => {
          if (!value) return callback(new Error(tt.value('loginReg.promptPasswordText')))
          if (!REGEXP_PWD.test(value)) return callback(new Error(tt.value('loginReg.formatPasswordText')))
          callback()
        },
        trigger: 'blur'
      }
    ]
  })
  return {
    passWordRule
  }
}
